<template>
  <div class="app-container">

    <el-form :inline="true" :model="searchForm" class="demo-form-inline">
      <el-form-item label="操作人">
        <el-input v-model="searchForm.name" placeholder="操作人"></el-input>
      </el-form-item>
      <el-form-item label="操作角色">
        <el-select v-model="searchForm.role" placeholder="操作角色">
          <el-option label="超级管理员" value="超级管理员"></el-option>
          <el-option label="普通管理员" value="普通管理员"></el-option>
          <el-option label="财务" value="财务"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click.native="reloadData()">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="描述">
        <template slot-scope="scope">
          {{ scope.row.description }}
        </template>
      </el-table-column>
      <el-table-column label="操作人" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.operatorName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作人账号" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.operateAccount }}
        </template>
      </el-table-column>
      <el-table-column label="操作人角色" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.operatorRole }}
        </template>
      </el-table-column>
      <el-table-column label="操作结果" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.result }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="创建时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { list } from '@/api/log'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      searchForm: {
        name: null,
        role: null
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData(name, role) {
      this.listLoading = true
      list({ pageSize: 10, pageCurrent: 1, roleName: role, userName: name }).then(response => {
        console.log(response)
        this.list = response.data.records
        this.listLoading = false
      })
    },
    reloadData() {
      this.fetchData(this.searchForm.name, this.searchForm.role)
    }
  }
}
</script>
